<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
  x:Class="OpenLS.Spreadsheet.UI.Internals.FormulaBarResources"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:ss="http://schemas.Kherty.com/office/2007/spreadsheet"
  xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI" 
  xmlns:oui="http://schemas.Kherty.com/office/2007" 
  xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals"
    >
    <ResourceDictionary.MergedDictionaries>
        <ssui:DefinedNamesResources/>
        <Internals:EditedCellResources/>
    </ResourceDictionary.MergedDictionaries>

    <DataTemplate DataType="{x:Type ss:Worksheet}" x:Key="formulaBarButtons">
        <StackPanel Orientation="Horizontal">
            <Button VerticalAlignment="Center"
        Style="{DynamicResource {x:Static oui:Styles.RibbonButtonStyleKey}}" Click="onCancel"
        x:Name="cancel">
                <Path Data='M0,0 L8,8 M 1.5,9 L 5,3 M2.5,9 L 5,3 L 8,1' StrokeThickness='1.5' x:Name='cancelPath'>
                    <Path.Stroke>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0" >
                            <GradientStop Offset="0" Color="#FFF98066" />
                            <GradientStop Offset="0.4925373134328358" Color="#FFFF5E3C" />
                            <GradientStop Offset="1" Color="#FFA81001" />
                        </LinearGradientBrush>
                    </Path.Stroke>
                </Path>
            </Button>
            <Button Grid.Column="1" VerticalAlignment="Center" Style="{DynamicResource {x:Static oui:Styles.RibbonButtonStyleKey}}"
              Click="onEnter"
              x:Name="enter">

                <Path Data='M0,0 M 0,5 L 4,9 L12,0 M 0,4 L 4,8 L12,0' StrokeThickness='1' x:Name='enterPath'>
                    <Path.Stroke>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0" >
                            <GradientStop Offset="0" Color="#FF4871C3" />
                            <GradientStop Offset="1" Color="#FF264990" />
                        </LinearGradientBrush>
                    </Path.Stroke>
                </Path>
            </Button>
            <Button Grid.Column="2" TextElement.FontStyle="Italic" TextElement.FontFamily="Cambria" VerticalAlignment="Center"
                 HorizontalAlignment="Right" Style="{DynamicResource {x:Static oui:Styles.RibbonButtonStyleKey}}" oui:RibbonElement.Icon="{x:Null}"
              Click="onInsertFunction"  Focusable="False">fx</Button>
            <!--to change-->

        </StackPanel>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.EditedCell)}" Value="{x:Null}">
                <Setter Property="Visibility" TargetName="cancel" Value="Hidden"/>
                <Setter Property="Visibility" TargetName="enter" Value="Hidden"/>
            </DataTrigger>
            <Trigger Property="IsMouseOver" Value="False" SourceName="enter">
                <Setter Property ="Stroke" Value="Black" TargetName="enterPath"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="False" SourceName="cancel">
                <Setter Property ="Stroke" Value="Black" TargetName="cancelPath"/>
            </Trigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    <DataTemplate DataType="{x:Type ss:Worksheet}" x:Key="formulaBar">
        <Grid TextElement.FontFamily="Segoe UI" TextBlock.FontSize="12" Background="White" Name="formulaGrid" ssui:SpreadsheetElement.Worksheet="{Binding}"
          MinHeight="20" ssui:SpreadsheetElement.WorksheetViewModel="{Binding Converter={x:Static Internals:SpreadsheetConverters.ViewModelFactory}}">
            <Grid.CommandBindings>
                <CommandBinding Command="{x:Static ssui:SpreadsheetCommands.InsertFunction}" Executed="onInsertFunction" CanExecute="onAlways"/>
            </Grid.CommandBindings>
            <Grid.RowDefinitions>
                <RowDefinition Height="20"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="160"/>
                <ColumnDefinition Width="12"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <ContentControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  Content="{Binding}" ContentTemplate="{StaticResource definedNames}" Name="definedNames" Focusable="False"/>
            <Path Margin="0.5 0.5 -0.5 -0.5" Data="M0,0 M10,0 L 70, 0 L70, 20 L 10 20 A 10,10,180,0 1 10,0"
            Fill="{DynamicResource {x:Static ss:SpreadsheetBrushes.FormulaBackgroundKey}}" Stroke="{DynamicResource {x:Static ss:SpreadsheetBrushes.FormulaBorderBrushKey}}" StrokeThickness="1" Grid.Column="1"
        Grid.ColumnSpan="2" HorizontalAlignment="Left">
            </Path>
            <Ellipse Margin="5 0 0 0" Height='8' Width='8' VerticalAlignment='Center' HorizontalAlignment='Left' Grid.Column='1' Grid.ColumnSpan='2'>
                <Ellipse.Fill>
                    <LinearGradientBrush  StartPoint='1 0' EndPoint='00 1'>
                        <GradientStop Offset="0" Color="#FF878D99" />
                        <GradientStop Offset="0.37499999999999961" Color="#FFC5CAD5" />
                        <GradientStop Offset="0.75000000000000078" Color="#FFF7F8F9" />
                        <GradientStop Offset="1" Color="#FFE9EBF1" />
                    </LinearGradientBrush>
                </Ellipse.Fill>
            </Ellipse>
            <ContentControl Grid.Column="2" Content="{Binding}" ContentTemplate ="{StaticResource formulaBarButtons}"  Focusable="False" Name="foo2" />
            <TextBox Margin="0" Grid.Column="3" Grid.RowSpan="2" VerticalScrollBarVisibility="Auto" VerticalContentAlignment="Top" Name="formulaEditor" KeyDown="onFormulaKeyDown" PreviewMouseDown="onFormulaMouseDown"
               Padding="2 0 0 0" HorizontalAlignment ="Stretch" VerticalAlignment ="Stretch" BorderThickness="0" TextWrapping="Wrap"
               Tag="{Binding ElementName=formulaEditor2}">
                <TextBox.Text>
                    <Binding Path="ActiveCell.LocalizedFormula" Mode="OneWay">
                        <Binding.Converter>
                            <Internals:FormattingConverter Format="{}{{{0}}}"></Internals:FormattingConverter>
                        </Binding.Converter>

                    </Binding>
                </TextBox.Text>
            </TextBox>
            <ContentControl 
        Margin="0" Grid.Column="3" Grid.RowSpan="2" VerticalContentAlignment="Stretch" Name="formulaEditor2"
        Background="Beige" ContentTemplate="{StaticResource FormulaEditedCell}"
        Content="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.EditedCell)}" Padding="2 0 0 0" HorizontalAlignment ="Stretch" VerticalAlignment ="Stretch"
/>
            <GridSplitter HorizontalAlignment ="Stretch" ResizeDirection="Columns" ResizeBehavior="PreviousAndNext" VerticalAlignment ="Stretch"
                    Background="Transparent" Grid.Column ="1" Name="splitter1" Focusable="False"></GridSplitter>
            <Rectangle HorizontalAlignment="Right" Grid.Column="2" Grid.RowSpan="2" Width="1" Fill="{DynamicResource {x:Static ss:SpreadsheetBrushes.FormulaBorderBrushKey}}" VerticalAlignment="Stretch"/>
            <Rectangle HorizontalAlignment="Stretch" Grid.ColumnSpan="3" Height="1" Grid.Row="1" Fill="{DynamicResource {x:Static ss:SpreadsheetBrushes.FormulaBorderBrushKey}}" VerticalAlignment="Top"/>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.EditedCell)}" Value="{x:Null}">
                <Setter TargetName ="formulaEditor2" Property="Visibility" Value="Hidden"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding ActiveCell.ArrayFormulaRange}" Value="{x:Null}">
                <Setter TargetName="formulaEditor" Property="Text">
                    <Setter.Value>
                        <Binding Path="ActiveCell.LocalizedFormula">
                        </Binding>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding ActiveCell.LocalizedFormula}" Value="{x:Null}">
                <Setter TargetName ="formulaEditor" Property="Text" Value="{Binding Path=ActiveCell.FormulaFormattedValue, Mode=OneWay}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding View.FormulasVisible}" Value="False">
                <Setter TargetName="formulaGrid" Property="Visibility"  Value="Collapsed" />
            </DataTrigger>
            <DataTrigger Binding="{Binding ElementName=formulaEditor, Path=(ssui:SpreadsheetElement.WorksheetViewModel).IsActiveCellFormulaVisible}" Value="False">
                <Setter TargetName ="formulaEditor" Property="Visibility" Value="Hidden"/>
            </DataTrigger>

        </DataTemplate.Triggers>
    </DataTemplate>


</ResourceDictionary>